using Devil;

namespace GameLogic
{
    public enum EFeatureSupport
    {
        Support,
        NotSupport,
        NotExecutable,
    }

    /// <summary>
    /// 可访问权限校验
    /// </summary>
    public interface IAccessable
    {
        Access GetExecutionAccess();
    }

    /// <summary>
    /// 全局访问权限校验，允许添加到 gameObject 上的组件校验其他行为的访问权限
    /// </summary>
    public interface IGlobalAccessable
    {
        /// <summary>
        /// 是否校验操作
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        bool IsValidator(object operation);
        Access GetExecutionAccess(object operation);
    }

    /// <summary>
    /// 访问权限信息
    /// </summary>
    public struct Access
    {
        int _fid;
        EFeatureSupport _access;
        public EFeatureSupport access => _access;
        public string title;
        public string detail;

        public bool IsObsolete
        {
            get
            {
                return _fid != ParallelUnity.frameCount;
            }
            set
            {
                if (value)
                    _fid = -1;
                else
                    _fid = ParallelUnity.frameCount;
            }
        }

        public Access(EFeatureSupport access)
        {
            this._fid = ParallelUnity.frameCount;
            this._access = access;
            this.title = string.Empty;
            this.detail = string.Empty;
        }

        public Access(EFeatureSupport access, string desc)
        {
            this._fid = ParallelUnity.frameCount;
            this._access = access;
            this.title = desc;
            this.detail = desc;
        }

        public Access(EFeatureSupport access, string title, string detail)
        {
            this._fid = ParallelUnity.frameCount;
            this._access = access;
            this.title = title;
            this.detail = detail;
        }

        public static implicit operator Access(EFeatureSupport support)
        {
            return new Access(support, string.Empty);
        }
    }

}